
import 'package:get/get.dart';

import 'state.dart';

class PreviewPhotoLogic extends GetxController {
  final state = PreviewPhotoState();

  @override
  void onInit() {
    Map args = Get.arguments;
    state.imgUrl = args['imgUrl'];
    state.msgId=args['msgId'];
    state.path=args['path'];
    super.onInit();
  }

  scaleUp() {
    state.scale *= 1.5;
    update();
  }

  ///记录上次scale的值,如果当前为放大手势并且scale大于记录的值,则直接使用scale
  ///如果小于记录的值,则记录值+当前scale和上次scale的差值
  double lastScale = 0;

  scaleDouble(double scale, double rotation) {
    if (rotation == 0) {
      ///如果是手指没有移动不做处理,同时抛弃掉一些细微移动
      return;
    }

    double diffScale = (scale - lastScale);
    if (diffScale < 0) {
      diffScale *= 4;
    }

    state.scale += diffScale;
    lastScale = scale;

    if (state.scale > state.MAX_SCALE) {
      state.scale = state.MAX_SCALE;
    }
    if (state.scale < state.MIN_SCALE) {
      state.scale = state.MIN_SCALE;
    }
    update();
  }

  reset() {
    state.scale = 1;
    update();
  }
}
